import ajax from "./axios.config";
export const reqGetCartApi = (page, size) => {
  return ajax({
    method: "get",
    url: "/cart",
    params: { page, size, random: Date.now() },
  });
};
//修改单个商品的选中状态
export const toggleSigleCartGoods = (id) => {
  return ajax({
    method: "patch",
    url: `/cart/select/${id}`,
  });
};
//修改所有商品的选中状态
export const toggleAllCartGoods = (flag) => {
  return ajax({
    method: "patch",
    url: "/cart/allSelect",
    data: { flag },
  });
};

//商品数量加1
export const reqGoodsNumsAdd = (id) => {
  return ajax({
    method: "patch",
    url: `/cart/num/add/${id}`,
  });
};

//商品数量减一
export const reqGoodsNumsReduce = (id) => {
  return ajax({
    method: "patch",
    url: `/cart/num/reduce/${id}`,
  });
};
//删除购物车里面的商品
export const reqDelCartGoods = (id) => {
  return ajax({
    method: "delete",
    url: "/cart",
    params: { id },
  });
};
//添加购物车商品
export const reqAddCartGoods = (goods_id, num) => {
  return ajax({
    method: "post",
    url: "/cart",
    data: { goods_id, num },
  });
};
//商品收藏
export const reqAddCollectApi = (id) => {
  return ajax({
    method: "post",
    url: "/user/favorite",
    data: { id },
  });
};

//取消商品收藏
export const reqDelCollectApi = (id) => {
  return ajax({
    method: "delete",
    url: `/user/favorite/${id}`,
  });
};
